home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / scopedisk24 / Qrt14src / qrt.h < prev    next >
C/C++ Source or Header  |  1988-08-23  |  9KB  |  334 lines

  1. /**********************************************************
  2.  
  3.  
  4.              Header file for Quick Ray Trace
  5.  
  6.                      Steve Koren
  7.  
  8.  **********************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <math.h>
  12.  
  13. #define TRUE  1
  14. #define FALSE 0
  15.  
  16. #define BOOL short
  17.  
  18. /**********************************************************
  19.  
  20.                      OBJECT  NUMBERS
  21.  
  22.  **********************************************************/
  23.  
  24. #define LINE               1
  25. #define SPHERE             2
  26. #define PARALLELOGRAM      3
  27. #define TRIANGLE           4
  28. #define LAMP               5
  29. #define OBSERVER           6
  30. #define GROUND             7
  31. #define SKY                8
  32. #define BBOX               9
  33. #define RING               10
  34. #define QUADRATIC          11
  35.  
  36.  
  37. /**********************************************************
  38.  
  39.                    PROGRAM CONSTANTS
  40.  
  41.  **********************************************************/
  42.  
  43. #define SMALL              1.0E-3
  44.  
  45. #define ASPECT  0.56       /* aspect ratio */
  46. #define CENTERX 160        /* center of screen */
  47. #define CENTERY 200
  48. #define XSIZE   320        /* x and y size */
  49. #define YSIZE   400
  50. #define CNUM    100        /* this many shades/color */
  51. #define SLEN    64         /* max string length */
  52. #define XSIZE4  80         /* xsize /4 */
  53. #define MAX_IX  4          /* maximum x interpolation */
  54. #define MAX_IY  4          /* maximum y interpolation */
  55.  
  56.  
  57. /**********************************************************
  58.  
  59.                       VECTOR STRUCTURES
  60.  
  61.  **********************************************************/
  62.  
  63. typedef struct vector {        /* a vector in 3 space */
  64.   float x,y,z;
  65. } VECTOR, *VECT_PTR;
  66.  
  67. typedef struct svector {       /* an r,g,b color vector */
  68.   short r,g,b;
  69. } SVECTOR, *SVECT_PTR;
  70.  
  71. typedef struct cinfo_struct {  /* color information */
  72.  
  73.   SVECTOR       amb,           /* ambient lighting */
  74.                 diff,          /* diffuse lighting */
  75.                 mirror,        /* % light reflected */
  76.                 trans;         /* % light transmitted */
  77.  
  78.   VECTOR        density;       /* density */
  79.  
  80.   float         sreflect,      /* specular refl coefficient */
  81.                 index;         /* index if refraction */
  82.  
  83.   short         fuzz,          /* currently unused */
  84.                 reflect,       /* percent specularly reflected */
  85.                 dither;        /* color dithering. 3..6 look ok */
  86.  
  87. } CINFO, *CINFO_PTR;
  88.  
  89.  
  90. /**********************************************************
  91.  
  92.                 PRECOMPUTED INFO FOR OBJECTS
  93.  
  94.  These fields can be used by object routines however
  95.  they wish.  They just make object/line intersections
  96.  faster.
  97.  
  98.  **********************************************************/
  99.  
  100. typedef struct _pre {
  101.  
  102.   float    sin1, cos1,         /* sin and cos */
  103.            sin2, cos2,
  104.            n1,                 /* misc number */
  105.            len1, len2;         /* lengths of vectors */
  106.  
  107.   VECTOR   vect1,              /* misc vector */
  108.            norm;               /* norm for planar objs */
  109.  
  110. } PRECOMP, PRECOMP_PTR;
  111.  
  112.  
  113. /**********************************************************
  114.  
  115.                       PATTERN STRUCTURE
  116.  
  117.  **********************************************************/
  118.  
  119. typedef struct patt {
  120.   short    type;               /* type of pattern */
  121.   float    xsize,              /* pattern size */
  122.            ysize,
  123.            startx,
  124.            starty,             /* x,y positions */
  125.            endx,
  126.            endy,
  127.            radius;             /* rad for circles */
  128.  
  129.   CINFO    cinfo;              /* color information */
  130.  
  131.   char     *name;              /* pattern name */
  132.  
  133.   struct patt *child, *sibling, *link;
  134.  
  135. } PATTERN, *PATTERN_PTR;
  136.  
  137.  
  138. /**********************************************************
  139.  
  140.                     OBJECT STRUCTURE
  141.  
  142.  **********************************************************/
  143.  
  144. typedef struct obj_struct {
  145.  
  146.   short         type,         /* object type */
  147.                 flag;         /* misc boolean flag */
  148.  
  149.   char          *name;        /* object name */
  150.  
  151.   VECTOR        loc,          /* object location */
  152.                 vect1,        /* three vectors */
  153.                 vect2,
  154.                 vect3,
  155.                 lower,        /* lower and upper bounds */
  156.                 upper;
  157.  
  158.   float         cterm,        /* for quadratic surfaces only */
  159.                 xmult,        /* x and y multipliers for patterns */
  160.                 ymult;
  161.  
  162.   CINFO         cinfo;        /* color information */
  163.  
  164.   PRECOMP       precomp;      /* precomputed information */
  165.  
  166.   struct obj_struct *nextobj, /* next obj in list */
  167.                     *child;   /* child for bounding boxes only */
  168.  
  169.   PATTERN_PTR   pattern,      /* pointer to pattern structure */
  170.                 remove;       /* remove section of object */
  171.  
  172. } OBJ_STRUCT, *OBJ_PTR;
  173.  
  174.  
  175. /**********************************************************
  176.  
  177.                    Plane Bbox structure
  178.  
  179.  **********************************************************/
  180.  
  181. typedef struct _PlaneBox {
  182.   int      min_x, min_y,
  183.            max_x, max_y;
  184.  
  185.   OBJ_PTR  object;
  186.  
  187.   struct _PlaneBox *next;
  188. } PLANE_BBOX, *PLANE_BBOX_PTR;
  189.  
  190.  
  191. /**********************************************************
  192.  
  193.                        WORLD STRUCTURE
  194.  
  195.  **********************************************************/
  196.  
  197. typedef struct world {
  198.   OBJ_PTR   stack,            /* here are the objects */
  199.             observer,         /* the observer */
  200.             sky,              /* sky */
  201.             lamps,            /* a lamp list */
  202.             instances;        /* instance list */
  203.  
  204.   int       objcount,         /* # objects and lamps */
  205.             lampcount,
  206.             first_scan,       /* first, last scan lines */
  207.             last_scan;
  208.  
  209.   long      ray_intersects,   /* statistics */
  210.             primary_traced,
  211.             to_lamp,
  212.             refl_trans,
  213.             bbox_intersects,
  214.             intersect_tests,
  215.             pixels_hit,
  216.             pattern_matches;
  217.  
  218.   VECTOR    obsright,         /* obs up dir */
  219.             obsup;
  220.  
  221.   SVECTOR   skycolor_horiz,   /* skycolors */
  222.             skycolor_zenith;
  223.  
  224.   PATTERN_PTR patlist;        /* the pattern stack */
  225.  
  226.   float     flength,          /* focal length */
  227.             globindex;        /* global index of refraction */
  228.  
  229.   char      *outfile;         /* output file name */
  230.   FILE      *filept;          /* output file pointer */
  231. } WORLD;
  232.  
  233.  
  234. /**********************************************************
  235.  
  236.                   FUNCTIONS FOR OBJECT TYPES
  237.  
  238.  **********************************************************/
  239.  
  240. typedef struct obj_data {
  241.   int (*ColTest)();           /* collision test function ptr */
  242.   int (*FindNorm)();          /* normal finding function ptr */
  243.   int (*FindBbox)();          /* object bound function ptr   */
  244.   int (*RelPos)();            /* object relative position    */
  245.   int (*PreComp)();           /* info pre-computing routine  */
  246.   int (*Offset)();            /* offset object by dx, dy, dz */
  247.   int (*Resize)();            /* resize object by a multiple */
  248. } OBJ_DATA;
  249.  
  250.  
  251. /**********************************************************
  252.  
  253.                       MATH DEFINES
  254.  
  255.  **********************************************************/
  256.  
  257. #define sqr(x) ((x)*(x))
  258. #define DotProd(v1,v2) (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z)
  259. #define MIN(x,y) ((x)<(y) ? (x) : (y))
  260. #define MAX(x,y) ((x)>(y) ? (x) : (y))
  261. #define IABS(x)  ((x)>0   ? (x) : (-(x)))
  262.  
  263.  
  264. /**********************************************************
  265.  
  266.                       Default structure
  267.  
  268.  **********************************************************/
  269.  
  270. typedef struct def_struct {
  271.  
  272.   CINFO cinfo;             /* default colorinfo */
  273.  
  274.   short shadow,            /* shadows ? */
  275.         vlamp,             /* lamps visible (not yet implimented) */
  276.         int_x,             /* interpolate (def=1) */
  277.         int_y;
  278.  
  279.   float threshold;         /* cutoff pt for min refl, refl rays */
  280.   short ithreshold;        /* integer version of above          */
  281.  
  282. } DEF, *DEF_PTR;
  283.  
  284. /**********************************************************
  285.  
  286.                      EXTERNAL DECLARATIONS
  287.  
  288.  **********************************************************/
  289.  
  290. extern DEF def;
  291.  
  292. extern OBJ_DATA ObjData[];
  293.  
  294. extern WORLD THEWORLD;
  295.  
  296. /**********************************************************
  297.  
  298.                        ERROR CODES
  299.  
  300.  **********************************************************/
  301.  
  302. #define ILLEGAL_PARAMETER 1
  303. #define TOO_FEW_PARMS     2
  304. #define ILLEGAL_OBJECT    3
  305. #define MALLOC_FAILURE    4
  306. #define SYNTAX_ERROR      5
  307. #define INTERNAL_ERROR    6
  308. #define FILE_ERROR        7
  309. #define PATTERN_NOT_FOUND 8
  310. #define PATTERN_EXISTS    9
  311. #define NO_OBSERVER       10
  312. #define UNDEFINED_PARAM   11
  313. #define NON_HOMOGENIOUS   12
  314. #define ZERO_INDEX        13
  315. #define COLOR_VALUE_ERR   14
  316. #define LESS_THAN_ZERO    15
  317. #define ZERO_MULTIPLIER   16
  318. #define UNDEFINED_NAME    17
  319. #define LPAREN_EXPECTED   18
  320. #define RPAREN_EXPECTED   19
  321. #define ILLEGAL_VECTOR    20
  322. #define ILLEGAL_SVECTOR   21
  323.  
  324.  
  325. /**********************************************************
  326.  
  327.  Define this flag for more robust code (HIGHLY recommended)
  328.  
  329.  **********************************************************/
  330.  
  331. #define ROBUST TRUE
  332.  
  333.  
  334.